/*
 * isWin standalone program header
 * Author: Travis Danniels
 */ 

/******************************************************************************
PROGRAM INPUT:

The AIs will receive the description of the board on standard input (stdin), 
as a single line, in the following form,

(num_col,num_row,last_col,total_game_time,player1_time,last_move_time,<s,b,g,r>,
 <s,b,g,r>,...,<s,b,g,r>)

where
    num_col            - is the number of columns in the board

    num_row            - is the number of rows in the board

    last_col           - is the column where the last move was made 
                         (the “top” piece in the last_col is piece which was 
                         last played by the competing AI)

    total_game_time    - is the total time which has been consumed since 
                         the game began

    player1_time       - is the total time which has been used by player1
                         (total_game_time - player1_time gives the total_time used 
                         by the opponent (player2))

    last_move_time     - is the time player2 spent making the their last move

    <s,b,g,r>          - is the piece which is currently in the given position
                         of the board (in column ordered from bottom to top and 
                         left to right from column 1 though column num_col 
                         see Figure 1) where s is space (an empty position),
                         r is red (a red piece occupies the position), 
                         g is green (a neutral piece occupies the position), 
                         and b is blue (a blue piece occupies the position).

Example vector:
7,6,3,600,290,20,r,b,s,s,s,s,b,b,r,g,s,s,b,r,b,b,g,s,r,g,r,b,s,s,r,r,
b,r,r,s,s,s,s,s,s,s,s,s,s,s,s,s
******************************************************************************/

#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>

#define NORTHWEST (0)
#define NORTH     (1) 
#define NORTHEAST (2)
#define EAST      (3)

// Index into a 1-d array as if it were 2-d
#define CELL(board, x, y, cols) (board [ y*cols + x ])
#define HASHED(scanHash, x, y, dir, cols) ( CELL(scanHash, x, y, cols) & ( 1 << dir ) )
#define SETHASH(scanHash, x, y, dir, cols) ( CELL(scanHash, x, y, cols) |= ( 1 << dir ) )

#define DEBUGB 0
#define DEBUG  0
#define DEBUG2 0
#define DEBUG3 0
/*
 * isWin:
 * - takes a vector as described in the PROGRAM INPUT section
 * - returns an integer that reflects the 'win value' of the input board
 */ 
int isWin ( char *board );

/*
 * scanCell:
 * - takes a position (x,y), a board matrix, and the dimensions of the board + a scan hash.
 * - returns 5 for a red type-1 win, -5 for a blue type-1 win
 *        or 4 for a red type-2 win, -4 for a blue type-2 win
 *        or 3 for a red type-3 win, -3 for a blue type-3 win
 *        or +-x where, in the case of simultaneous winning runs, x is the 
 *           maximal winning run of the player with the highest total win
 *           value (see project description for better description)
 *        or 0 for an cell which is not a part of any wins.
 */
int scanCell ( int x, int y, char *board );


/*
 * Given a 4-char winning run (not null-terminated), returns its win value
 */
int getRunValue ( char *run );

/*
 * scanEast
 */
int scanEast ( int x, int y, char *board );

/*
 * scanNorth
 */
int scanNorth ( int x, int y, char *board );

/*
 * scanNorthEast
 */
int scanNorthEast ( int x, int y, char *board );

/*
 * scanNorthWest
 */
int scanNorthWest ( int x, int y, char *board );

/*
 * verifyWin
 * - takes ... 
 * - returns the board's true win value (suitable for the program's output)
 */
int verifyWin ( char *board, int *run_coords );

